#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

void Swap(int* p1, int* p2)
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

int HSort(int* a, int left, int right)
{
	int prev = left;
	int cur = left + 1;
	int keyi = left;
	while (cur <= right)
	{
		if (a[cur] < a[keyi])
		{
			prev++;
			Swap(&a[prev], &a[cur]);
		}

		cur++;
	}

	Swap(&a[prev], &a[keyi]);
	keyi = prev;
	return keyi;
}

void Qsort(int* a, int begin, int end)
{
	if (begin >= end)
		return;
	int keyi = HSort(a, begin, end);
	Qsort(a, begin, keyi - 1);
	Qsort(a, keyi + 1, end);
}

void print(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
}

int main()
{
	int a[] = { 5, 4, 8, 7, 2, 3, 1, 9, 10,6 };
	Qsort(a, 0, 9);
	print(a, 10);
}